﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OnTheWay.Domain
{
    public static class DataService<TIService>
    {
        static TIService _service;
        static string _url = "";//e'g:http://localhost:4934/Service1.svc?wsdl

        /// <summary>
        /// debug模式
        /// </summary>
        public static bool IsDebug { get; set; }

        /// <summary>
        /// 数据服务Url，例如：http://localhost:4934/Service1.svc?wsdl
        /// </summary>
        public static string Url
        {
            get { return DataService<TIService>._url; }
        }

        /// <summary>
        /// 获取数据服务代理
        /// </summary>
        public static TIService Service
        {
            get
            {
                //if (string.IsNullOrEmpty(_url))
                //{
                //    throw new Exception("未设置数据服务Url。");
                //}

                if (_service == null)
                {
                    _service = (TIService)typeof(TIService).Assembly.CreateInstance(typeof(TIService).FullName);//InvokeContext.CreateWCFServiceByURL<TIService>(_url);
                }
                return _service;
            }
        }

        public static void SetWebServiceUrl(string url)
        {
            _url = url;
        }
    }
}
